//
//  TestViewController.m
//  OCUI
//
//  Created by Mac on 15-11-6.
//  Copyright (c) 2015年 King. All rights reserved.
//

#import "TestViewController.h"
#import "KingViewController.h"


@interface TestViewController ()
{
    NSArray *data;
    NSArray *datail;
    NSArray *headers;
}


@end

@implementation TestViewController


//二维数组数据链接
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.text = data[indexPath.section][indexPath.row];
    //cell.detailTextLabel.text = datail[indexPath.row];
    
    //详细按钮
    
    cell.accessoryType = UITableViewCellAccessoryDetailButton;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIViewController *con = [UIViewController new];
    [self.navigationController pushViewController:con animated:YES];
}

//导航栏
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"通讯录";
    }
    return self;
}

//数组
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    data = @[
             @[@"安妮",@"安全"],
             @[@"白壳",@"白起"]
             ];
    datail = @[
               @"King",
               @"111111111"
               ];
    headers = @[
                @"A",
                @"B",
                ];
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

//通讯录推动字母
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return headers[section];
}

//二维数组链接
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return data.count;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{

    
}


//删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSMutableArray *arr = data.mutableCopy;
        [arr removeObjectAtIndex:indexPath.row];
        data = arr;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
//        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

    
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
